<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:UML="http://www.omg.org/UML"  exclude-result-prefixes="UML">

<xsl:key name="classId" match="//Class[@xmi.id] | //Enumeration[@xmi.id] | //AssociationClass[@xmi.id]" use="@xmi.id"/>

<xsl:key name="attributeId" match="//Model[@xmi.id]/Namespace.ownedElement/Foundation.Data_Types.Enumeration[@xmi.id] | //DataType[@xmi.id] | //Class[@xmi.id]" use="@xmi.id"/>

<xsl:variable name="GraphicPositionScale" select="1 div 3"/>
<xsl:variable name="GraphicSizeScale" select="1 div 3"/>

<xsl:template match="/">
<UMLEditor>
	<Model>
		<!-- Package -->
		<xsl:apply-templates select="//Model[@xmi.id]"/>
		
		<!-- Héritage -->
		<xsl:apply-templates select="//Generalization[@xmi.id]"/>
		
		<!-- Implémentation -->
		<xsl:apply-templates select="//Classifier.realization"/>
		
		<!-- Association -->
		<xsl:apply-templates select="//Association[@xmi.id]" mode="Association"/>
		<xsl:apply-templates select="//AssociationClass[@xmi.id]" mode="Association"/>

	</Model>
	
	<GraphicView>
	
		<xsl:for-each select="//Class[@xmi.id]">
			<xsl:variable name="stereotype" select="ModelElement.stereotype/Stereotype/ModelElement.name"/>
			
			<xsl:choose>
				<xsl:when test="$stereotype='Enumeration'">
					<!-- EnumerationControl -->
					<xsl:apply-templates select="." mode="EnumerationControl"/>
				</xsl:when>
				
				<xsl:otherwise>
					<!-- ClassControl pour les classes-->
					<xsl:apply-templates select="." mode="ClassControl"/>
				</xsl:otherwise>
			</xsl:choose>
			
		</xsl:for-each>
		
		<!-- ClassControl pour les classes d'association -->
		<xsl:apply-templates select="//AssociationClass[@xmi.id]" mode="ClassControl"/>

		<!-- ClassControl pour les interfaces -->
		<xsl:apply-templates select="//Interface[@xmi.id]" mode="ClassControl"/>

		<!-- GeneralizationControl -->
		<xsl:apply-templates select="//Generalization[@xmi.id]" mode="GeneralizationControl"/>
		
		<!-- ImplementationControl -->
		<xsl:apply-templates select="//Classifier.realization" mode="ImplementationControl"/>
		
		<!-- AssociationControl -->
		<xsl:apply-templates select="//Association[@xmi.id]" mode="AssociationControl"/>
		<xsl:apply-templates select="//AssociationClass[@xmi.id]" mode="AssociationControl"/>

	</GraphicView>	
</UMLEditor>
</xsl:template>

<!-- Model (Package) -->
<xsl:template match="Model">
	<xsl:element name="Package">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"/>
		
		<xsl:for-each select=".//Class[@xmi.id]">
			<xsl:variable name="stereotype" select="ModelElement.stereotype/Stereotype/ModelElement.name"/>
			<xsl:apply-templates select="." mode="Class"/>
		</xsl:for-each>

		<!-- énumérations -->
		<xsl:apply-templates select="//Enumeration"/>

		<!-- classe d'association -->
		<!--<xsl:apply-templates select="//AssociationClass[@xmi.id]" mode="AssociationClass"/>-->
		
		<!-- interfaces -->
		<xsl:apply-templates select="./Namespace.ownedElement/Interface[@xmi.id]" mode="Interface"/>
		
	</xsl:element>
</xsl:template>

<!-- Classes -->
<xsl:template match="Class" mode="Class">
	<xsl:element name="Class">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation">
			<xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/>
		</xsl:attribute>
		<xsl:attribute name="visibility">v_<xsl:value-of select="ModelElement.visibility/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="abstract"><xsl:value-of select="GeneralizableElement.isAbstract/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="final">false</xsl:attribute>
		
		<xsl:variable name="stereotype" select="ModelElement.stereotype/Stereotype/ModelElement.name"/>
		<xsl:attribute name="stereotype"><xsl:value-of select="$stereotype"/></xsl:attribute>
		
		<xsl:attribute name="associationClass">
			<xsl:choose>
				<xsl:when test="count(./Namespace.ownedElement/AssociationClass[@xmi.id])>0">
					<xsl:text>true</xsl:text>		
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>false</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
			
		<!-- Attributs -->
		<xsl:apply-templates select="Classifier.feature/Attribute[@xmi.id]" mode="Property"/>
		
		<!-- Operations -->
		<xsl:apply-templates select="Classifier.feature/Operation[@xmi.id]" mode="Operation"/>
		
	</xsl:element>
</xsl:template>

<!-- Attributs -->
<xsl:template match="Attribute" mode="Property">
	<xsl:element name="Property">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		
	<!--	<xsl:choose>
			
			<xsl:when test="StructuralFeature.type/Foundation.Data_Types.Enumeration">
				<xsl:variable name="idvalue" select="StructuralFeature.type/Foundation.Data_Types.Enumeration/@xmi.idref"/>
				
				<xsl:choose>
					<xsl:when test="key('attributeId',$idvalue)/ModelElement.name = '&lt;undefined&gt;'">
						<xsl:attribute name="type">void</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="type"><xsl:value-of select="key('attributeId',$idvalue)/ModelElement.name"/></xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				
			</xsl:when>
			
			
			<xsl:when test="StructuralFeature.type/DataType">
				<xsl:variable name="idvalue" select="StructuralFeature.type/DataType/@xmi.idref"/>
				
				<xsl:choose>
					<xsl:when test="key('attributeId',$idvalue)/ModelElement.name = '&lt;undefined&gt;'">
						<xsl:attribute name="type">void</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="type"><xsl:value-of select="key('attributeId',$idvalue)/ModelElement.name"/></xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>

			</xsl:when>
		</xsl:choose>-->
		
		<xsl:variable name="idvalue" select="StructuralFeature.type/child::node()/@xmi.idref"/>
		
		<xsl:choose>
			<xsl:when test="key('attributeId',$idvalue)/ModelElement.name = '&lt;undefined&gt;'">
				<xsl:attribute name="type">void</xsl:attribute>
			</xsl:when>
			<xsl:otherwise>
				<xsl:attribute name="type"><xsl:value-of select="key('attributeId',$idvalue)/ModelElement.name"/></xsl:attribute>
			</xsl:otherwise>
		</xsl:choose>
		
		
		<xsl:attribute name="visibility">v_<xsl:value-of select="ModelElement.visibility/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="static">???</xsl:attribute>
		<xsl:attribute name="defaultValue"><xsl:value-of select="Attribute.initialValue/Foundation.Data_Types.Expression/Foundation.Data_Types.Expression.body"/></xsl:attribute>

		<xsl:variable name="idType" select="StructuralFeature.type/child::node()/@xmi.idref"/>
		<xsl:variable name="stereotype" select="ModelElement.stereotype/Stereotype/ModelElement.name"/>
		
		<xsl:if test="$stereotype = 'Enumeration' ">
			<xsl:attribute name="isEnum">true</xsl:attribute>
		</xsl:if>
			
	</xsl:element>
</xsl:template>

<!-- Operations -->
<xsl:template match="Operation" mode="Operation">
	<xsl:element name="Operation">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		
		<xsl:variable name="returnTypeIdValue" select=".//Parameter[@xmi.id]/Parameter.kind[@xmi.value='return']/../Parameter.type/DataType/@xmi.idref "/>

		<xsl:attribute name="type"><xsl:value-of select="key('attributeId', $returnTypeIdValue)/ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="visibility">v_<xsl:value-of select="ModelElement.visibility/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="static">???</xsl:attribute>
		<xsl:attribute name="modifier">m_none</xsl:attribute>
		<xsl:attribute name="code"/>
		
		<xsl:for-each select="BehavioralFeature.parameter/Parameter/Parameter.kind[@xmi.value='inout']/..">
			<xsl:element name="Parameter">
				<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
				
				<xsl:variable name="idvalue" select="Parameter.type/DataType/@xmi.idref"/>
								
				<xsl:attribute name="type"><xsl:value-of select="key('attributeId', $idvalue)/ModelElement.name"/></xsl:attribute>
				<xsl:attribute name="documentation"/>
			</xsl:element>
		</xsl:for-each>
		
		
	</xsl:element>
</xsl:template>

<!-- Interface -->
<xsl:template match="Interface" mode="Interface">
	<xsl:element name="Interface">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		<xsl:attribute name="visibility">v_<xsl:value-of select="ModelElement.visibility/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="final">???</xsl:attribute>
		
		<!-- Attributs -->
		<xsl:apply-templates select="Classifier.feature/Attribute[@xmi.id]" mode="Property"/>
		
		<!-- Operations -->
		<xsl:apply-templates select="Classifier.feature/Operation[@xmi.id]" mode="Operation"/>
		
	</xsl:element>
</xsl:template>


<!-- Enumeration -->
<xsl:template match="Enumeration" >
	<xsl:element name="Enumeration">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		<xsl:attribute name="visibility">v_<xsl:value-of select="ModelElement.visibility/@xmi.value"/></xsl:attribute>
		<xsl:attribute name="final">???</xsl:attribute>
		
		<!-- Literal -->
		<xsl:apply-templates select="Enumeration.literal/EnumerationLiteral"/>
		
	</xsl:element>
</xsl:template>

<!-- literal -->
<xsl:template match="EnumerationLiteral">
	<xsl:element name="Property">
		<xsl:attribute name="name"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		<xsl:attribute name="type"/>
		<xsl:attribute name="visibility"/>
		<xsl:attribute name="static"/>
		<xsl:attribute name="defaultValue"/>

	</xsl:element>
</xsl:template>


<!-- l'héritage -->
<xsl:template match="Generalization">
	<xsl:element name="Generalization">
		<xsl:attribute name="name"><xsl:apply-templates select="." mode="GetGeneralizationName"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		<xsl:variable name="idvalue1" select="Generalization.child/GeneralizableElement/@xmi.idref"/>
		<xsl:variable name="idvalue2" select="Generalization.parent/GeneralizableElement/@xmi.idref"/>
		<xsl:attribute name="clientClassName"><xsl:value-of select="key('classId',$idvalue1)/ModelElement.name"/></xsl:attribute>
		<xsl:attribute name="supplierClassName"><xsl:value-of select="key('classId',$idvalue2)/ModelElement.name"/></xsl:attribute>
	</xsl:element>
</xsl:template>

<!-- retourne le nom de l'héritage -->
<xsl:template match="Generalization" mode="GetGeneralizationName">
	<xsl:choose>
		<xsl:when test="ModelElement.name != '' "><xsl:value-of select="ModelElement.name"/></xsl:when>
		<xsl:otherwise><xsl:value-of select="@xmi.id"/></xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- l'implémentation -->
<xsl:template match="Classifier.realization">
	<xsl:for-each select="Class">
		<xsl:element name="Implementation">
			<xsl:attribute name="name"><xsl:value-of select="../../../Interface/@xmi.id"/><xsl:value-of select="@xmi.idref"/></xsl:attribute>
			<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
			<xsl:variable name="idvalue" select="@xmi.idref"/>
			<xsl:attribute name="clientClassName"><xsl:value-of select="key('classId',$idvalue)/ModelElement.name"/></xsl:attribute>
			<xsl:attribute name="supplierClassName"><xsl:value-of select="../../ModelElement.name"/></xsl:attribute>
		</xsl:element>
	</xsl:for-each>
</xsl:template>

<!-- l'Association -->
<xsl:template match="Association" mode="Association">
	<xsl:element name="Association">
		<xsl:attribute name="name"><xsl:apply-templates select="ModelElement.name" mode="GetAssociationName"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		<xsl:attribute name="type"><xsl:apply-templates select="Association.connection" mode="GetAssociationType"/></xsl:attribute>
		<xsl:attribute name="navigable"><xsl:apply-templates select="Association.connection" mode="GetAssociationNavigability"/></xsl:attribute>

		<xsl:variable name="client"><xsl:apply-templates select="Association.connection" mode="GetAssociationClient"/></xsl:variable>
		<xsl:variable name="supplier"><xsl:apply-templates select="Association.connection" mode="GetAssociationSupplier"/></xsl:variable>

		<xsl:attribute name="associationClassifier"/>
		
		<xsl:attribute name="clientClassName">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationClassName"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientRole">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationRoleName"><xsl:with-param name="role" select="$client"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientMultiplicity">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationMultiplicity"><xsl:with-param name="role" select="$client"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientQualifierName"/>
		<xsl:attribute name="clientQualifierType"/>
		<xsl:attribute name="supplierClassName">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationClassName"><xsl:with-param name="role" select="$client"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierRole">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationRoleName"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierMultiplicity">
			<xsl:apply-templates select="Association.connection" mode="GetAssociationMultiplicity"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierQualifierName"></xsl:attribute><!-- non défini -->
		<xsl:attribute name="supplierQualifierType"></xsl:attribute>
	</xsl:element>
</xsl:template>

<!-- l'Association avec classe d'association-->
<xsl:template match="AssociationClass" mode="Association">
	<xsl:element name="Association">
		<xsl:attribute name="name"><xsl:apply-templates select="ModelElement.name" mode="GetAssociationName"/></xsl:attribute>
		<xsl:attribute name="documentation"><xsl:apply-templates select="ModelElement.taggedValue" mode="GetDocumentation"/></xsl:attribute>
		
		<!-- recherche de l'association concernée -->
		<xsl:variable name="idRelation" select="Namespace.ownedElement/Association/@xmi.idref" />
		
		<xsl:attribute name="type"><xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationType"/></xsl:attribute>
		<xsl:attribute name="navigable"><xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationNavigability"/></xsl:attribute>

		<xsl:variable name="client"><xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationClient"/></xsl:variable>
		<xsl:variable name="supplier"><xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationSupplier"/></xsl:variable>

		
		<!-- recherche de la classe d'association concernée -->
		<xsl:variable name="idClass" select="Namespace.ownedElement/Class/@xmi.idref" />
		
		<xsl:attribute name="associationClassifier"><xsl:value-of select="//Class[@xmi.id=$idClass]/ModelElement.name"/></xsl:attribute>
		
		<xsl:attribute name="clientClassName">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationClassName">
				<xsl:with-param name="role" select="$client"/>
			</xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientRole">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationRoleName"><xsl:with-param name="role" select="$client"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientMultiplicity">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationMultiplicity"><xsl:with-param name="role" select="$client"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="clientQualifierName"/>
		<xsl:attribute name="clientQualifierType"/>
		<xsl:attribute name="supplierClassName">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationClassName"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierRole">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationRoleName"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierMultiplicity">
			<xsl:apply-templates select="//Association[@xmi.id=$idRelation]/Association.connection" mode="GetAssociationMultiplicity"><xsl:with-param name="role" select="$supplier"/></xsl:apply-templates>
		</xsl:attribute>
		<xsl:attribute name="supplierQualifierName"></xsl:attribute><!-- non défini -->
		<xsl:attribute name="supplierQualifierType"></xsl:attribute>
	</xsl:element>
</xsl:template>


<!-- retourne le nom de l'association -->
<xsl:template match="ModelElement.name" mode="GetAssociationName">
	<xsl:choose>
		<xsl:when test="node() != '' "><xsl:value-of select="node()"/></xsl:when>
		<xsl:otherwise><xsl:value-of select="../@xmi.id"/></xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- retourne le type de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationType">
	<xsl:variable name="class1" select="AssociationEnd[1]/AssociationEnd.aggregation/@xmi.value"/>
	<xsl:variable name="class2" select="AssociationEnd[2]/AssociationEnd.aggregation/@xmi.value"/>

	<xsl:choose>
		<xsl:when test="$class1='none' and $class2='none'">association</xsl:when>
		<xsl:when test="$class1='aggregate' or $class2='aggregate'">aggregation</xsl:when>
		<xsl:when test="$class1='composite' or $class2='composite'">composition</xsl:when>
		
		<!-- Visio -->
		<xsl:when test="$class1='partag' or $class2='partag' ">aggregation</xsl:when> <!-- paratgé -->
	</xsl:choose>
</xsl:template>

<!-- retourne le client de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationClient">
	<xsl:variable name="class1" select="AssociationEnd[1]/AssociationEnd.aggregation/@xmi.value"/>

	<xsl:choose>
		<xsl:when test="$class1='none'">1</xsl:when>
		<xsl:otherwise>2</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- retourne le supplier de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationSupplier">
	<xsl:variable name="class1" select="AssociationEnd[1]/AssociationEnd.aggregation/@xmi.value"/>

	<xsl:choose>
		<xsl:when test="$class1='none'">2</xsl:when>
		<xsl:otherwise>1</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- retourne la navigabilité de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationNavigability">
	
	<xsl:variable name="client"><xsl:apply-templates select="Association.connection" mode="GetAssociationClient"/></xsl:variable>
	
	<xsl:variable name="clientNavigability" select="AssociationEnd[position()=$client]/AssociationEnd.isNavigable/@xmi.value"/>
	
	<xsl:variable name="associationType"><xsl:apply-templates select="." mode="GetAssociationType"/></xsl:variable>
	
	<xsl:choose>
		<xsl:when test="$associationType='association'">false</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="$clientNavigability='true'">false</xsl:when>
				<xsl:otherwise>true</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>

</xsl:template>

<!-- retourne le nom de la classe client/supplier de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationClassName">
	<xsl:param name="role"/>
	
	<xsl:variable name="clientId" select="AssociationEnd[position()=$role]/AssociationEnd.participant/Classifier[1]/@xmi.idref"/>

	<xsl:value-of select="key('classId', $clientId)/ModelElement.name"/>	
</xsl:template>

<!-- retourne le role du client/supplier de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationRoleName">
	<xsl:param name="role"/>
	
	<xsl:value-of select="AssociationEnd[position()=$role]/ModelElement.name"/>	
</xsl:template>

<!-- retourne la multiplicité du client/supplier de l'association -->
<xsl:template match="Association.connection" mode="GetAssociationMultiplicity">
	<xsl:param name="role"/>
	
	<xsl:variable name="xmiMultiplicityLower" select="AssociationEnd[position()=$role]/AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/MultiplicityRange.lower"/>
	<xsl:variable name="xmiMultiplicityUpper" select="AssociationEnd[position()=$role]/AssociationEnd.multiplicity/Multiplicity/Multiplicity.range/MultiplicityRange/MultiplicityRange.upper"/>
	<xsl:variable name="xmiMultiplicity"><xsl:value-of select="$xmiMultiplicityLower"/>..<xsl:value-of select="$xmiMultiplicityUpper"/></xsl:variable>
	
	<!-- teste si la relation est une composition -->
	<xsl:variable name="type"><xsl:apply-templates mode="GetAssociationType" select="." /></xsl:variable>
	<xsl:choose>
		<xsl:when test="$xmiMultiplicity='1..1'">1</xsl:when>
		<xsl:when test="$xmiMultiplicity='*..*'">0..*</xsl:when>
		<!--<xsl:when test="$xmiMultiplicity='..' and $type='composition' and AssociationEnd[position()=$role]/AssociationEnd.aggregation[@xmi.value='none']">0..1</xsl:when>-->
		<xsl:otherwise><xsl:value-of select="$xmiMultiplicity"/></xsl:otherwise>
	</xsl:choose>
</xsl:template>


<!-- *************************** GraphicView *************************** -->

<!-- classes graphiques -->
<xsl:template match="Class" mode="ClassControl">

	<!-- recherche l'élément graphique associé -->
	<xsl:variable name="idvalue" select="@xmi.id"/>
	<xsl:variable name="body" select="//Foundation.Auxiliary_Elements.Presentation[@xmi.id]/Foundation.Auxiliary_Elements.Presentation.model/Class[@xmi.idref=$idvalue]/../../Foundation.Auxiliary_Elements.Presentation.geometry/Foundation.Data_Types.Geometry/Foundation.Data_Types.Geometry.body"/>

	<xsl:element name="ClassControl">
		
		<xsl:call-template name="ComputeSize"><xsl:with-param name="body" select="$body"/></xsl:call-template>
		
		<xsl:attribute name="id"><xsl:value-of select="$idvalue"/></xsl:attribute>
		<xsl:attribute name="boundClassName"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
	</xsl:element>

</xsl:template>

<!-- classes d'association graphiques -->
<xsl:template match="AssociationClass" mode="ClassControl">

	<!-- recherche l'élément graphique associé -->
	<xsl:variable name="idvalue" select="@xmi.id"/>
	<xsl:variable name="body" select="//Foundation.Auxiliary_Elements.Presentation[@xmi.id]/Foundation.Auxiliary_Elements.Presentation.model/AssociationClass[@xmi.idref=$idvalue]/../../Foundation.Auxiliary_Elements.Presentation.geometry/Foundation.Data_Types.Geometry/Foundation.Data_Types.Geometry.body"/>

	<xsl:element name="ClassControl">
		
		<xsl:call-template name="ComputeSize"><xsl:with-param name="body" select="$body"/></xsl:call-template>
		
		<xsl:attribute name="id"><xsl:value-of select="$idvalue"/></xsl:attribute>
		<xsl:attribute name="boundClassName"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
	</xsl:element>

</xsl:template>

<!-- énumérations graphiques -->
<xsl:template match="Class" mode="EnumerationControl">

	<!-- recherche l'élément graphique associé -->
	<xsl:variable name="idvalue" select="@xmi.id"/>
	<xsl:variable name="body" select="//Foundation.Auxiliary_Elements.Presentation[@xmi.id]/Foundation.Auxiliary_Elements.Presentation.model/Class[@xmi.idref=$idvalue]/../../Foundation.Auxiliary_Elements.Presentation.geometry/Foundation.Data_Types.Geometry/Foundation.Data_Types.Geometry.body"/>

	<xsl:element name="EnumerationControl">
		
		<xsl:call-template name="ComputeSize"><xsl:with-param name="body" select="$body"/></xsl:call-template>
		
		<xsl:attribute name="id"><xsl:value-of select="$idvalue"/></xsl:attribute>
		<xsl:attribute name="boundEnumerationName"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
	</xsl:element>

</xsl:template>

<!-- interfaces graphiques -->
<xsl:template match="Interface" mode="ClassControl">
	
	<!-- recherche l'élément graphique associé -->
	<xsl:variable name="idvalue" select="@xmi.id"/>
	<xsl:variable name="body" select="//Foundation.Auxiliary_Elements.Presentation[@xmi.id]/Foundation.Auxiliary_Elements.Presentation.model/Interface[@xmi.idref=$idvalue]/../../Foundation.Auxiliary_Elements.Presentation.geometry/Foundation.Data_Types.Geometry/Foundation.Data_Types.Geometry.body"/>

	<xsl:element name="InterfaceControl">
		
		<xsl:call-template name="ComputeSize"><xsl:with-param name="body" select="$body"/></xsl:call-template>
		
		<xsl:attribute name="id"><xsl:value-of select="$idvalue"/></xsl:attribute>
		<xsl:attribute name="boundInterfaceName"><xsl:value-of select="ModelElement.name"/></xsl:attribute>
	</xsl:element>
	
</xsl:template>

<!-- retourne la documentation d'une entitée -->
<xsl:template match="ModelElement.taggedValue" mode="GetDocumentation">
	
	<xsl:value-of select="Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag = 'documentation']/Foundation.Extension_Mechanisms.TaggedValue.value"/>

</xsl:template>


<!-- créer les attributs location et size -->
<xsl:template name="ComputeSize">
	<xsl:param name="body"/>
	
	<xsl:variable name="Xcenter" select="number(substring-before($body, ',')) * $GraphicPositionScale"/>
	<xsl:variable name="tmp1" select="substring-after($body, ',')"/>
	<xsl:variable name="Ycenter" select="number(substring-before($tmp1, ',')) * $GraphicPositionScale"/>
	<xsl:variable name="tmp2" select="substring-after($tmp1, ',')"/>
	<xsl:variable name="width" select="number(substring-before($tmp2, ',')) * $GraphicSizeScale"/>
	<xsl:variable name="tmp3" select="substring-after($tmp2, ',')"/>
	<xsl:variable name="height" select="number(substring-before($tmp3, ',')) * $GraphicSizeScale"/>
	
	<xsl:attribute name="location">{X=0,Y=0}</xsl:attribute>
	<xsl:attribute name="size">{X=0,Y=0}</xsl:attribute>

</xsl:template>


<!-- relation d'héritage graphique -->
<xsl:template match="Generalization" mode="GeneralizationControl">
	<xsl:element name="GeneralizationControl">
		<xsl:attribute name="boundGeneralization"><xsl:apply-templates select="." mode="GetGeneralizationName"/></xsl:attribute>
		<xsl:attribute name="boundClientControl"><xsl:value-of select="Generalization.subtype/Class/@xmi.idref"/></xsl:attribute>
		<xsl:attribute name="boundSupplierControl"><xsl:value-of select="Generalization.supertype/Class/@xmi.idref"/></xsl:attribute>
	</xsl:element>
</xsl:template>

<!-- relation d'implémentation graphique -->
<xsl:template match="Classifier.realization" mode="ImplementationControl">
	
	<xsl:for-each select="Class">
		<xsl:element name="ImplementationControl">
			<xsl:attribute name="boundImplementation"><xsl:value-of select="../../../Interface/@xmi.id"/><xsl:value-of select="@xmi.idref"/></xsl:attribute>
			<xsl:attribute name="boundClientControl"><xsl:value-of select="@xmi.idref"/></xsl:attribute>
			<xsl:attribute name="boundSupplierControl"><xsl:value-of select="../../../Interface/@xmi.id"/></xsl:attribute>
		</xsl:element>
	</xsl:for-each>
	
</xsl:template>

<!-- relation d'association graphique -->
<xsl:template match="Association" mode="AssociationControl">
	
	<xsl:variable name="client"><xsl:apply-templates select="Association.connection" mode="GetAssociationClient"/></xsl:variable>
	<xsl:variable name="supplier"><xsl:apply-templates select="Association.connection" mode="GetAssociationSupplier"/></xsl:variable>
	
	<xsl:element name="AssociationControl">
		<xsl:attribute name="boundAssociation"><xsl:apply-templates select="Association.connection" mode="GetAssociationName"/></xsl:attribute>
		<xsl:attribute name="boundClientControl"><xsl:value-of select="Association.connection/AssociationEnd[position()=$client]/AssociationEnd.participant/Classifier[1]/@xmi.idref"/></xsl:attribute>
		<xsl:attribute name="boundSupplierControl"><xsl:value-of select="Association.connection/AssociationEnd[position()=$supplier]/AssociationEnd.participant/Classifier[1]/@xmi.idref"/></xsl:attribute>
	</xsl:element>

</xsl:template>

<!-- relation d'association graphique -->
<xsl:template match="AssociationClass" mode="AssociationControl">
	
	<xsl:variable name="client"><xsl:apply-templates select="Association.connection" mode="GetAssociationClient"/></xsl:variable>
	<xsl:variable name="supplier"><xsl:apply-templates select="Association.connection" mode="GetAssociationSupplier"/></xsl:variable>
	 
	<xsl:element name="AssociationControl">
		<xsl:attribute name="boundAssociation"><xsl:apply-templates select="Association.connection" mode="GetAssociationName"/></xsl:attribute>
		<xsl:attribute name="boundClientControl"><xsl:value-of select="Association.connection/AssociationEnd[position()=$client]/AssociationEnd.participant/Classifier[1]/@xmi.idref"/></xsl:attribute>
		<xsl:attribute name="boundSupplierControl"><xsl:value-of select="Association.connection/AssociationEnd[position()=$supplier]/AssociationEnd.participant/Classifier[1]/@xmi.idref"/></xsl:attribute>
	</xsl:element>

</xsl:template>

</xsl:stylesheet>
